home *** CD-ROM | disk | FTP | other *** search
- PROGRAM lpatch ;
- { patch the labels program to work with any printer }
-
- CONST
- {$I GEMCONST.PAS}
- pgmname = 'LABELS.PRG';
-
- numcodes = 12;
- codelen = 8;
-
- OFF = FALSE;
- ON = TRUE;
-
- START_POS = $0D44;
- MAGIC_POS = $0D3E;
- TYPE
- {$I gemtype.pas}
- codearray = array[1..numcodes] of str255;
- pgmfile = packed file of byte;
-
- VAR
- infile : pgmfile;
- msg,inpath : str255;
- ok_button : integer;
- i,j,k,start,size : integer;
- found : boolean;
- code,entry : codearray;
- MAGIC : string[5];
-
- {$I gemsubs}
-
- { *************************************************************************** }
-
- procedure show_edit_funcs;
- { shows form edit functions available to user }
-
- var help_box : dialog_ptr; { the form itself }
- i,
- ok_button, { the exit button }
- pushed : integer; { button the user pushed }
-
- item : array[1..7] of integer; { the text lines }
- line : array[1..7] of string[48];
-
- begin
-
- { initialize the lines }
- line[1] := ' EDIT FUNCTIONS';
- line[2] := '';
- line[3] := 'Esc - Erases entire line';
- line[4] := 'arrows - Move up/down lines';
- line[5] := 'arrows - Move left/right';
- line[6] := 'Delete - Erase character right';
- line[7] := 'Backspace - Erase character left';
-
- { create the object }
- help_box := New_Dialog(9,0,0,36,12);
-
- { add the text lines }
- for i := 1 to 7 do begin
- item[i] := Add_DItem(help_box,G_String,None,2,i,34,1,0,0);
- Set_Dtext(help_box,item[i],line[i],System_font,TE_Left);
- end;
-
- { add an ok button }
- ok_button := Add_Ditem(help_box,G_Button,
- Selectable | Exit_Btn | Default,14,9,8,2,0,0);
- set_Dtext(help_box,ok_button,'OK',System_font,TE_Center);
-
- { reserve room to center the dialog }
- Center_dialog(help_box);
-
- { display the box }
- pushed := Do_Dialog(help_box,0);
-
- { erase it }
- End_dialog(help_box);
-
- { release the space }
- { Delete_Dialog(help_box);
- }
- end;
-
-
- { *************************************************************************** }
-
- procedure get_codes;
-
- const
- PROMPT1 = 'Enter codes for your printer (DECIMAL)';
- PROMPT2 = 'Use ''99,99,99'' if option not available';
-
- BOX_WID = 50; { must be longer than prompt }
- BOX_HGT = 21; { must be at least numcodes + 9 }
- BTN_WID = 8; { 3 * BTN_WID <= BOX_WID - 4 }
- BTN_HGT = 2;
- BTN_MARGIN = 5; { best if 4*BTN_MARGIN + 3*BTN_WID = BOX_WID }
-
- var
- the_box : dialog_ptr; { name of the box }
- prompt_item, { name of the prompt }
- ok,help,quit, { the exit buttons }
- pushed, { which one the user exited with }
- i : integer; { loop variable }
-
- line : array[1..numcodes] of integer; { name of the edit lines }
- template,valid,init : array[1..numcodes] of string[BOX_WID];
-
- begin
- Init_Mouse;
- { create the box }
- the_box := New_Dialog(numcodes + 7,0,0,BOX_WID,BOX_HGT);
-
- { add the prompts }
- prompt_item := Add_Ditem(the_box,g_text,None,0,1,BOX_WID,1,0,
- 256*BLACK+128);
- Set_Dtext(the_box,prompt_item,PROMPT1,System_font,TE_Center);
- prompt_item := Add_Ditem(the_box,g_text,None,0,2,BOX_WID,1,0,
- 256*BLACK+128);
- Set_Dtext(the_box,prompt_item,PROMPT2,System_font,TE_Center);
-
- { set up template and validation strings }
- template[1] := 'Software Reset.............:__,__,__';
- template[2] := 'Normal print (pica-10cpi)..:__,__,__';
- template[3] := 'Double wide print..........:__,__,__';
- template[4] := 'Condensed print(compressed):__,__,__';
- template[5] := 'line spacing 1/8"..........:__,__,__';
- template[6] := 'line spacing 1/6"..........:__,__,__';
- template[7] := 'Underline mode on..........:__,__,__';
- template[8] := 'Underline mode off.........:__,__,__';
- template[9] := 'Italic character set.......:__,__,__';
- template[10] := 'Cancel italics.............:__,__,__';
- template[11] := 'Bold or Emphasized print...:__,__,__';
- template[12] := 'Cancel Emphasized print....:__,__,__';
-
- init[1] := '276400';
- init[2] := '276601';
- init[3] := '271400';
- init[4] := '271500';
- init[5] := '274800';
- init[6] := '275000';
- init[7] := '274501';
- init[8] := '274500';
- init[9] := '275200';
- init[10] := '275300';
- init[11] := '276900';
- init[12] := '277000';
-
-
- for i := 1 to numcodes do begin
- valid[i] := '999999';
- end;
-
- { add the edit lines }
- for i := 1 to numcodes do begin
- line[i] := Add_Ditem(the_box,G_Ftext,None,1,3+i,BOX_WID,1,0,
- 256*BLACK+128);
- Set_Dedit(the_box,line[i],template[i],valid[i],init[i],
- System_font,TE_Center);
- end;
-
- { add the exit buttons }
- ok := Add_Ditem(the_box,G_button,Selectable | Exit_Btn,
- BTN_MARGIN,numcodes+5,BTN_WID,BTN_HGT,
- 0,0);
- Set_Dtext(the_box,ok,'OK',System_font,TE_Center);
- help := Add_Ditem(the_box,G_button,Selectable | Exit_Btn,
- (BOX_WID-BTN_WID)DIV 2,numcodes+5,BTN_WID,BTN_HGT,
- 0,0);
- Set_Dtext(the_box,help,'HELP',System_font,TE_Center);
- quit := Add_Ditem(the_box,G_button,Selectable | Exit_Btn,
- BOX_WID-BTN_WID-BTN_MARGIN,numcodes+5,BTN_WID,BTN_HGT,
- 0,0);
- Set_Dtext(the_box,quit,'QUIT',System_font,TE_Center);
-
- repeat { center the box }
-
- Center_dialog(the_box);
-
- { display it }
- pushed := Do_Dialog(the_box,line[1]);
-
- { erase it }
- End_dialog(the_box);
-
- if pushed = quit then halt;
-
- if pushed = help then begin
- Obj_SetState(the_box,help,Normal,False);
- show_edit_funcs;
- end;
-
- until pushed = ok;
- { get the users entries }
- for i := 1 to numcodes do begin
- Get_Dedit(the_box,line[i],entry[i]);
- end;
-
- end; { of procedure dialog }
-
- { *************************************************************************** }
-
- procedure get_path(var path : str255);
- { finds and returns the default path including drive }
-
- var i,drive : integer;
-
- procedure d_getpath(var buf:str255; drv:integer); GEMDOS($47);
- function d_getdrv : integer ; GEMDOS($19);
-
- begin
- drive := d_getdrv;
- d_getpath(path,drive+1);
- i:=1;
- while path[i] <> chr(0) do begin
- i := i +1;
- end;
- path[0] := chr(i-1);
- if i > 1 then path := concat(path,'\');
- path := concat('A:\',path);
- path[1] := chr(ord('A') + drive);
- end;
-
- { *************************************************************************** }
-
- procedure patch ( position : integer; new_val : byte ) ;
- { patch new_val into file infile at position - assumes f is open }
- { too bad file value parameters are not allowed }
- begin
- get(infile,position);
- infile^ := new_val;
- put(infile,position);
- end;
-
- { *************************************************************************** }
-
- BEGIN
- { IF Init_Gem >= 0 THEN }
- BEGIN
- MAGIC := '$3ABH';
- { Introduce self }
- msg := '[0][ Modify LABELS.PRG? | version 1.1| ][ DO IT | ABORT ]';
- ok_button := Do_Alert(msg,1);
- if ok_button = 2 then halt;
-
- { set path names for infile and outfile }
- get_path(inpath);
- inpath := concat(inpath,pgmname);
-
- { Is LABELS.PRG there? }
- Reset(infile,inpath);
- if eof(infile) then begin
- msg := '[2][ Couldn''t Open |';
- msg := concat(msg,' LABELS.PRG| | ][ ABORT ]');
- ok_button := Do_Alert(msg,1);
- close(infile);
- halt;
- end;
-
- { verify magic # }
- for i := 0 to 4 do begin
- get(infile,MAGIC_POS + i);
- if infile^ <> ord(MAGIC[i+1]) then begin
- msg := '[2][ Incompatable version |';
- msg := concat(msg,' of LABELS.PRG| | ][ ABORT ]');
- ok_button := Do_Alert(msg,1);
- close(infile);
- halt;
- end;
- end;
-
- { get new escape codes }
- get_codes;
-
- { convert entries to codes - insert commas }
- for i := 1 to numcodes do begin
- for j := 1 to 2 do
- insert(',',entry[i],j*3);
- code[numcodes-i+1] := entry[i];
- end;
-
- { put new codes in file }
- start := START_POS;
- for i := 1 to numcodes do
- for j := 1 to codelen do begin
- patch(start,ord(code[i,j]));
- start := start + 1;
- end;
-
- close(infile);
-
- Exit_Gem ;
- END ;
- END.
-